package com.ruoyi.epidemic.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.epidemic.domain.TbCity;
import com.ruoyi.epidemic.service.ITbCityService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 城市信息Controller
 * 
 * @author ruoyi
 * @date 2023-03-21
 */
@RestController

@RequestMapping("/epidemic/city")
public class TbCityController extends BaseController
{
    @Autowired
    private ITbCityService tbCityService;

    /**
     * 查询城市信息列表
     */
    @PreAuthorize("@ss.hasPermi('epidemic:city:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbCity tbCity)
    {
        startPage();
        List<TbCity> list = tbCityService.selectTbCityList(tbCity);
        return getDataTable(list);
    }

    /**
     * 导出城市信息列表
     */
    @PreAuthorize("@ss.hasPermi('epidemic:city:export')")
    @Log(title = "城市信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbCity tbCity)
    {
        List<TbCity> list = tbCityService.selectTbCityList(tbCity);
        ExcelUtil<TbCity> util = new ExcelUtil<TbCity>(TbCity.class);
        util.exportExcel(response, list, "城市信息数据");
    }

    /**
     * 获取城市信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('epidemic:city:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tbCityService.selectTbCityById(id));
    }

    /**
     * 新增城市信息
     */
    @PreAuthorize("@ss.hasPermi('epidemic:city:add')")
    @Log(title = "城市信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbCity tbCity)
    {
        return toAjax(tbCityService.insertTbCity(tbCity));
    }

    /**
     * 修改城市信息
     */
    @PreAuthorize("@ss.hasPermi('epidemic:city:edit')")
    @Log(title = "城市信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbCity tbCity)
    {
        return toAjax(tbCityService.updateTbCity(tbCity));
    }

    /**
     * 删除城市信息
     */
    @PreAuthorize("@ss.hasPermi('epidemic:city:remove')")
    @Log(title = "城市信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbCityService.deleteTbCityByIds(ids));
    }
}
